//------------------------------------------------------------------------------
// X2TK Graphic Toolkit
// Copyright (C) 2006-2007 Janusz Kowalski
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------

#include "x2tk_Widget.h"
#include "RawVector.h"
#include "fontSDL.h"

#ifndef X2TK_TEXTFIELD_H
#define X2TK_TEXTFIELD_H

namespace x2tk {

static const unsigned TF_V_MARGIN = 4;

class TextField : public Widget {
  private:
    RawVector<char> text_;
    Font font_;
    // Position of the cursor.
    unsigned i_;
    // Displacement of the text (in pixels).
    unsigned d_;
    
    void dalign() {
      if(16*i_-d_>getW()-TF_V_MARGIN) {
        d_=16*i_-getW()+TF_V_MARGIN;
      } else if(16*i_-d_<0+TF_V_MARGIN) {
        d_=16*i_-TF_V_MARGIN;
      }
    }
  public:
    TextField(int x, int y, int w, int h);
    
    virtual void event_key(const SDL_KeyboardEvent& key);
    
    virtual void draw(GraphicContext &g);
    
    virtual bool mouseDown(int type);

    virtual void event(EV ev);
    
    ~TextField();
};

} // namespace x2tk

#endif
